home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / include / MotifApp / ColorModel.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-17  |  2.0 KB  |  66 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. ////////////////////////////////////////////////////////////
  22. // ColorModel.h: An RGB color model for a single color
  23. ////////////////////////////////////////////////////////////
  24. #ifndef COLORMODEL_H
  25. #define COLORMODEL_H
  26.  
  27. class ColorView;
  28.  
  29. class ColorModel {
  30.     
  31.   private:
  32.     
  33.     int         _numViews;  // Number of dependent views
  34.     ColorView **_views;     // View objects that depend on this model
  35.     
  36.     int      _red;          // RGB representation of a color
  37.     int      _green;
  38.     int      _blue;
  39.     
  40.     // Called whenever the model's data changes
  41.     
  42.     void     updateViews();
  43.     
  44.   public:
  45.     
  46.     ColorModel();
  47.     
  48.     // Add dependent View objects
  49.     
  50.     void attachView ( ColorView * );
  51.     
  52.     // Functions that allow controllers to manipulate the Model
  53.     
  54.     void setRgb   ( int, int, int );   
  55.     void setRed   ( int r ) { setRgb ( r,    _green, _blue ); }
  56.     void setGreen ( int g ) { setRgb ( _red, g,      _blue ); }
  57.     void setBlue  ( int b ) { setRgb ( _red, _green,  b    ); }
  58.     
  59.     // Functions that allow Views to retrieve the Model's current state
  60.     
  61.     int  red()   { return _red;   }
  62.     int  green() { return _green; }
  63.     int  blue()  { return _blue;  }
  64. };
  65. #endif
  66.